import TableData from "@/components/public/el-tables";
import TableLyout from '@/components/commonPublic/tableLyout.vue'
import tree from "@/components/materialDataManage/tree"; //左侧机构树
import {
    saveStationWarn, // 查询-拌合站预警信息-新增接口
    getStationWarnByCompanyId, // 查询-拌合站预警信息-详情接口
    getUserCompanyTreeList, //树状图
} from "@/api/request.js";
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import formJs from "./regexDetail.js"; //新增弹框配置
import {
    statusType2
} from "@/utils/config"; //配置项

export default {
    name: "experimentalClosureProcess",
    data() {
        return {
            name: "experimentalClosureProcess",
            defaultProps: {
                children: "children",
                label: "fShortname",
            },
            treeText: {
                companyId: null,
                userId: null,
            },
            companyTree: "", //所有数据
            treeData: [], //左侧树状图数据
            // 机构树
            highlightBd: true, //左侧机构树停留背景色
            treelength: false, //左侧树显示隐藏
            // checked: true, //查看下级按钮
            showName: "未选择公司",
            checkData: [], //树状图默认选中id


            isLock: false,
            projectId: null,
            projectName: null,
            loading: false,
            btnObj: [], //按钮
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件

            radio: "待办",
            // 列表
            getList: {
                fCompanyid: "", //左侧选中组织机构id
                keyType: "", //上方查询条件材料种类
                page: 1, //当前页码
                pageSize: 20, //每页显示条数
                userId: "", //查询待办或已办时传 列表页查询不传
                modelType: 2, //0-待办 1-已办 传2 表示列表页查询

            },
            isShow: false, //是否显示弹框

            statusNum: null, //点击那个按钮
            dataFid: null, //列表详情id
            currentRow: null, //列表详情
            activeIndex: "1",
            fId: null, //当前数据fId

            companyId: null,
            currentRowId: "",
            dialogTitle: null,
            fAduitUser1List: [], //一级审核拼接
            fAduitUser2List: [], //一级审核拼接
            fAduitUser3List: [], //一级审核拼接
            fAduitUser4List: [], //一级审核拼接
            fAduitUser5List: [], //一级审核拼接
           
           
            tableData: [], //表格列表数据列表
            // 拌和站列表配置项
            table_config: {
                classCell: true,
                thead: [{
                        label: "",
                        prop: "name",
                        minWidth: "35px",
                        filter: true,
                        btn: true,
                        align: "center",
                        colorName: "",
                        callback: (rowData) => {
                            let data = statusType2[rowData.name];
                            if (data) {
                                return data.label;
                            }
                        },
                        specialClass: (rowData) => {
                            let data = statusType2[rowData.name];
                            if (data) {
                                return data.className;
                            }
                        },
                    },
                    {
                        label: "水(%)",
                        prop: "water",
                        minWidth: "35px",
                        type: "number",
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center",
                    },
                    {
                        label: "水泥(%)",
                        prop: "cement",
                        minWidth: "35px",
                        type: "number",
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center",
                    },

                    {
                        label: "骨料(%)",
                        prop: "aggregate",
                        minWidth: "35px",
                        type: "number",
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center",
                    },
                    {
                        label: "粉煤灰(%)",
                        prop: "flyash",
                        minWidth: "35px",
                        type: "number",
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center",
                    },
                    {
                        label: "矿粉(%)",
                        prop: "oredesign",
                        minWidth: "35px",
                        type: "number",
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center",
                    },
                    {
                        label: "外加剂(%)",
                        prop: "admixture",
                        minWidth: "35px",
                        type: "number",
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center",
                    },
                    {
                        label: "闭合流程",
                        prop: "examine",
                        minWidth: "60px",
                        type: "option",
                        disabled: false, //是否禁用
                        option: true,
                        align: "center",
                        options: [{
                                value: "无需闭合",
                                label: "无需闭合",
                            },
                            {
                                value: "一级流程",
                                label: "一级流程",
                            },
                            {
                                value: "二级流程",
                                label: "二级流程",
                            },
                            {
                                value: "三级流程",
                                label: "三级流程",
                            },
                            {
                                value: "四级流程",
                                label: "四级流程",
                            },
                            {
                                value: "五级流程",
                                label: "五级流程",
                            },
                        ],
                    },
                    {
                        label: "一级审核",
                        prop: "examine0",
                        minWidth: "60px",
                        type: "option",
                        disabled: false, //是否禁用
                        option: true,
                        options: [],
                        align: "center",
                    },
                    {
                        label: "二级审核",
                        prop: "examine1",
                        minWidth: "60px",
                        type: "option",
                        disabled: false, //是否禁用
                        option: true,
                        options: [],
                        align: "center",
                    },
                    {
                        label: "三级审核",
                        prop: "examine2",
                        minWidth: "60px",
                        type: "option",
                        disabled: false, //是否禁用
                        option: true,
                        options: [],
                        align: "center",
                    },
                    {
                        label: "四级审核",
                        prop: "examine3",
                        minWidth: "60px",
                        type: "option",
                        disabled: false, //是否禁用
                        option: true,
                        options: [],
                        align: "center",
                    },
                    {
                        label: "五级审核",
                        prop: "examine4",
                        minWidth: "60px",
                        type: "option",
                        disabled: false, //是否禁用
                        option: true,
                        options: [],
                        align: "center",
                    },
                ],
                isCheckBox: false,
                isIndex: false,
                isOperation: true,
            },
        };

    },
    components: {
        TableLyout,

        TableData,
        tree,
        elBreadcrumb,

    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
        if (JSON.parse(sessionStorage.getItem("GxBack-materialDataManage_treeCheck"))) {
            var id = JSON.parse(sessionStorage.getItem("GxBack-materialDataManage_treeCheck"));
            this.checkData = [id.fCompanyid];
        }
        this.yj_searchForm(this.getList);
        this.getTree();

        this.btnRole(this.name)
    },
    methods: {
        refreshList() { //刷新列表

            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },
        // 重置按钮
        modelType(e) {
            this.fId = "";
            if (e == "待办") {
                this.getList.modelType = "0";
            } else {
                this.getList.modelType = "1";
            }
            this.yj_searchForm(this.getList);
        },
        closeDialog() {
            this.isShow = false;
        },

        // 左侧树结构
        getTree() {
            this.treeText.companyId = this.userInfo.companyId;
            this.treeText.userId = this.userInfo.userId;
            getUserCompanyTreeList(this.treeText)
                .then((res) => {
                    if (res.errcode == 0) {
                        var companyTree = res.data.userCompanyTreeList;
                        this.treeData = this.commonJs.tranListToTreeData(companyTree);
                        if (this.treeData[0].children == undefined) {
                            this.treelength = false; //左侧组织机构是否显示
                        } else {
                            this.treelength = true;
                        }

                        if (this.checkData[0]) {
                            this.showName = JSON.parse(
                                sessionStorage.getItem("GxBack-materialDataManage_treeCheck")
                            ).fShortname;
                            this.getList.fCompanyid = this.checkData[0];
                        } else {
                            this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
                            this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
                            this.checkData[0] = this.treeData[0].fCompanyid;
                        }
                        console.log('jjjj', this.getList.fCompanyid);
                        this.yj_searchForm(this.getList); // 调用主页面列表接口
                        // 列表
                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },
        // 点击左侧机构树
        handleNodeClick(data) {
            this.showName = data.fShortname; //顶部显示机构名
            this.getList.fCompanyid = data.fCompanyid;
            this.getList.page = 1;
            this.getList.pageSize = 20;

            this.yj_searchForm(this.getList);
        },
        handleRow() {},
        btnRole(name) {
            if (this.userInfo.userId != 'System') {
                var btnList = [];
                var ModuleList = JSON.parse(sessionStorage.getItem("GxBack-ModuleList"));
                if (ModuleList.length > 0) {
                    ModuleList.map((item) => {
                        if (item.fEncode == name) {
                            btnList = item.modulebuttonList;
                        }
                    });
                    btnList.map(item => {
                        item['disabled'] = false
                    })
                    this.btnObj = btnList
                }
            } else {
                this.btnObj = formJs.btnObj
            }
        },
        getBtnName(name, status) {
            this.statusNum = status
            this.yj_edit(status)
        },

        // 新增/编辑
        yj_edit(num) {
            if (this.userInfo.userId == 'System') {
                this.statusNum = num
                this.dialogTitle = "材料存放位置"
                if (num == 1) { //新增
                    this.editText();
                } else if (num == 2) { // 编辑
                    if (this.dataFid != null) {
                        this.editText();
                    } else {
                        this.$message.warning("请先选择需要编辑的数据");
                    }
                } else if (num == 3) { //删除
                    if (this.dataFid != null) {
                        this.yj_delete()
                    } else {
                        this.$message.warning("请先选择需要删除的数据");
                    }
                } else if (num == 7) {
                    if (this.dataFid != null) {
                        this.statusNum = 7
                        this.isShow = true;
                        this.dialogTitle = "材料存放位置"
                    } else {
                        this.$message.warning("请先选择需要查看的数据");
                    }
                }

            } else {
                this.$message.warning("该用户无法新增");
            }
        },
        editText() {
            this.isShow = true;
        },

   
        // 查看
        // 点击查看
        yj_viewForm(row, label) {
            if (label == "存放位置") {
                this.statusNum = 7
                this.isShow = true;
                this.dialogTitle = "材料存放位置"


            }
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val
            this.dataFid = val.fId;
        },
     


    },
};